/**
 * @param b64Data
 * @returns {Promise<string>}
 * @deprecated
 */
export function base64ToLocal(b64Data: string) {
  const fsm = uni.getFileSystemManager()
  const [, format, bodyData] =
    /data:image\/(\w+)(?:\+.+)?;base64,(.*)/.exec(b64Data) || []
  if (!format) {
    throw Error('ERROR_BASE64SRC_PARSE')
  }

  console.log(bodyData)

  const FILE_BASE_NAME = 'tmp_base64src'

  const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.png`
  const buffer = uni.base64ToArrayBuffer(bodyData)

  return new Promise<string>((resolve, reject) => {
    fsm.writeFile({
      filePath,
      data: b64Data,
      encoding: 'base64',
      success: () => {
        resolve(filePath)
      },
      fail: reject
    })
  })
}
